package cn.itlaobing.springmvc.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;

import cn.itlaobing.springmvc.dao.YikeMapper;
import cn.itlaobing.springmvc.entity.Yike;
import cn.itlaobing.springmvc.service.YikeService;

@Service
public class YikeServiceImpl implements YikeService {

	
	@Autowired
	private YikeMapper yikeMapper;
	
	//查询
    @Override
	public List<Yike> findBySearchFilter(Map<String,String> searchFilter) {
		
		if(searchFilter==null){
			searchFilter=new HashMap<>();
		}else{
			if(StringUtils.isBlank(searchFilter.get("pageNum"))){
				searchFilter.put("pageNum","1");
				
			}
			if(StringUtils.isBlank(searchFilter.get("pageSize"))){
				searchFilter.put("pageSize","3");
			}
		}		
		PageHelper.startPage(searchFilter); //map中需要包含 pageNum 和pageSize
		return yikeMapper.findBySearchFilter(searchFilter);
	}


    //保存，添加
	@Override
	public void save(Yike yike) {
		yikeMapper.insert(yike);
	}

	//通过ID查找
	@Override
	public Yike findById(Integer id) {
		
		return yikeMapper.selectByPrimaryKey(id);
	}

    //修改
	@Override
	public void update(Yike yike) {
			yikeMapper.updateByPrimaryKeySelective(yike);
	}

	//删除
	@Override
	public void delete(Integer id) {
		
		yikeMapper.deleteByPrimaryKey(id);
	}

	//树形菜单查询
	@Override
	public List<Yike> findAll() {
		
		return yikeMapper.findAll();
	}

}
